package com.sanley.piss.web.service;


import com.sanley.piss.mapper.WorkExperienceMapper;
import com.sanley.piss.model.ServiceImpl;
import com.sanley.piss.model.StringUtil;
import com.sanley.piss.model.exceptionUtil.exception.ServiceException;
import com.sanley.piss.model.exceptionUtil.json.ResultEnum;
import com.sanley.piss.model.po.WorkExperience;
import com.sanley.piss.web.service.mapper.IWorkExperienceService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Create By  on 2021/3/13.
 * @author 张凯大天才
 */
@Service
@Primary
public class WorkExperienceServiceImpl extends ServiceImpl<WorkExperienceMapper, WorkExperience> implements IWorkExperienceService {

    @Override
    public void insert(WorkExperience workExperience, Integer userId) {
        workExperience.setEmployeeId(userId);
        workExperience.setGmtCreate(LocalDateTime.now());
        baseMapper.insert(workExperience);
    }

    @Override
    public void batchInsert(List<WorkExperience> lists) {
        lists.forEach(list->{
            list.setGmtCreate(LocalDateTime.now());
        });
        baseMapper.batchInsert(lists);
    }

    @Override
    public WorkExperience selectById(Integer id) {
        WorkExperience workExperience = baseMapper.selectById(id);
        if (StringUtil.isNull(workExperience)) {
            throw new ServiceException(ResultEnum.roleIsNull);
        }
        return workExperience;
    }
}
